package com.dongdongshop.servcice.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.pojo.TbTypeTemplateExample;
import com.dongdongshop.service.TemplateServcie;
import com.dongdongshop.util.PageBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class TemplateServiceImpl implements TemplateServcie {
    @Resource
    private TbTypeTemplateMapper templateMapper;

    @Override
    public PageBean<TbTypeTemplate> getTemplate(String name, Integer pageNumber, Integer pageSize) {
        PageBean<TbTypeTemplate> page =new PageBean<>();
        page.setPageNumber(pageNumber);
        page.setPageSize(pageSize);
        List<TbTypeTemplate> list = templateMapper.getTemplate(name,page.getStartIndex(),pageSize);
        List<TbTypeTemplate> tbTypeTemplates = templateMapper.selectByExample(new TbTypeTemplateExample());
        page.setTotalCount(tbTypeTemplates.size());
        page.setResult(list);
        return page;
    }

    @Override
    public void insertTemplate(TbTypeTemplate template) {
        templateMapper.insertSelective(template);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        templateMapper.deleteBatch(ids);
    }

    @Override
    public TbTypeTemplate updateInfo(Integer id) {
        TbTypeTemplate template = templateMapper.selectByPrimaryKey(Long.valueOf(id));
        return template;
    }

    @Override
    public void update(TbTypeTemplate template) {
        templateMapper.updateByPrimaryKeySelective(template);
    }

    @Override
    public List<TbTypeTemplate> getTemplateAllInfo() {
        List<TbTypeTemplate> tbTypeTemplates = templateMapper.selectByExample(new TbTypeTemplateExample());
        return tbTypeTemplates;
    }

    @Override
    public TbTypeTemplate getBrandByTypeid(Integer typeId) {
        TbTypeTemplate template = templateMapper.selectByPrimaryKey(Long.valueOf(typeId));
        return template;
    }
}
